package com.example.myapplication;

import com.example.myapplication.restructure.TestClass;
import com.example.myapplication.restructure.ValueConvertUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {

    public static void main(String[] args) {

        Object a = 1f;
//        System.out.println(ValueConvertUtils.convertFloat(a));
//        System.out.println(ValueConvertUtils.convertInt(a));
//        System.out.println(ValueConvertUtils.convertBoolean(a));
     //   System.out.println(obj2Float(a));

        int[] oldIds = new int[]{1, 2, 3, 4, 5};
        int[] newIds = new int[]{};
        List<Integer> result = getNeedCancelIds(oldIds,newIds);
        for(Integer integer : result){
            System.out.println(integer);
        }
    }

    public static float obj2Float(Object obj) {
        float value = -1.0f;
        if (obj instanceof Integer) {
            value = (float) ((int) obj);
        } else if (obj instanceof Float) {
            value = (float) obj;
        } else if (obj instanceof Boolean) {
            value = (boolean) obj ? 1.0f : 0.0f;
        } else if (obj instanceof Double) {
            value = (float) ((double) obj);
        }
        return (float) (Math.round(value * 10)) / 10;
    }

    private static List<Integer> getNeedCancelIds(int[] oldIds, int[] newIds) {
        List<Integer> needCancelIds = new ArrayList<>(oldIds.length);
        for (int oldId : oldIds) {
            boolean flag = false;
            for (int newId : newIds) {
                if (newId == oldId) {
                    //新的数组还能找到这个id，通知就不需要取消
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                //新的数组里面已经不存在这个id，需要取消通知
                needCancelIds.add(oldId);
            }
        }
        return needCancelIds;
    }

}
